package com.adee.nowcoder.huawei;

import java.util.Scanner;

public class T045_HJ045 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            int n = Integer.parseInt(in.nextLine());
            for(int i = 0; i < n; i++) {
                String s = in.nextLine();
                System.out.println(calc(s));
            }
        }
    }
    public static int calc(String s) {
        int[] arr = new int[26];
        for(int i = 0; i < s.length(); i++) {
            int k = (int)(s.charAt(i)-'a');
            arr[k] += 1;
        }
        //print(arr);
        for(int i = arr.length-1; i > 0; i--) {
            for(int j = 0; j < i; j++) {
                if(arr[j] < arr[j+1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
        //print(arr);
        // Arrays.sort(arr);
        int sum = 0;
        for(int i = 0; i < arr.length; i++) {
            sum += ((26-i)*arr[i]);
        }
        return sum;
    }

    public static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }
}
